import request from '../../../../../public/js/common/api/api.js';

const ScmUrl = Utils.CurDomain.ScmInventory;
const MasterDataUrl = Utils.CurDomain.MasterDataUrl;
const SysPlfUrl = Utils.CurDomain.SysPlfUrl;
const CBSUrl = Utils.CurDomain.CBSUrl;
const AuthUrl = Utils.CurDomain.AuthUrl;


/**
 * @file领用单API
 */
export default class stocktransferApi {
    //获取用户拥有的组织
    static getOrgList() {
        return request.get(`${AuthUrl}/accounts/orgs`);
    }

    /**
     * 获取领用单详情
     * @param {*} id
     * @returns
     */
    static getStockTransferBill(id) {
        return request.get(`${ScmUrl}/stocktransferbills/${id}`, undefined, true);
    }

    /**
     * 删除领用单
     * @returns
     */
    static deleteStockTransferBill(id) {
        return request.delete(`${ScmUrl}/stocktransferbills/${id}`, undefined, true);
    }

    /**
     * 更新领用单
     * @returns
     */
    static updateStockTransferBill(id, data) {
        return request.put(`${ScmUrl}/stocktransferbills/${id}`, data, true);
    }

    /**
     * 查询领用单列表
     * @returns
     */
    static getStockTransferBillList(data) {
        return request.post(`${ScmUrl}/stocktransferbills/plist`, data);
    }

    /**
     * 添加领用单
     * @param {*} data
     * @returns
     */
    static addStockTransferBill(data) {
        return request.post(`${ScmUrl}/stocktransferbills`, data);
    }

    /**
     * 批量提交与审核
     * @param {*} ids
     * @param {*} isAudit
     * @returns
     */
    static billStatusDispose(ids, status, isRollback = false) {
        let _json = {
            1: [`/submit/${ids}`, 2],
            2: [`/audit/${ids}`, 3]
        }
        let _jsonRoll = {
            2: [`/resubmit/${ids}`, 1],
            3: [`/reaudit/${ids}`, 2]
        }

        let _url = isRollback ? _jsonRoll[status][0] : _json[status][0];
        return request.put(`${ScmUrl}/stocktransferbills${_url}`, undefined, true)
    }

    /**
     * 获取物料信息
     * @returns
     */
    static getMaterial() {
        return request.get(`${MasterDataUrl}/yymaterials`)
    }

    /**
     * 查询仓库信息
     * @returns
     */
    static getYfWareHouseList(id) {
        return request.get(`${ScmUrl}/yywarehouses/by/q?StorageOrgUnitId=${id}`)
    }

    /**
     * 查询仓库信息
     * @returns
     */
    static getBaseOrgUnitList(aotype = 10, upoid = 'ooca') {
        return request.get(`${SysPlfUrl}/yyorgunits/by/q?upoid=${upoid}&aotype=${aotype}`)
    }

    /**
     * 根据仓库获取物料
     * @param {} id
     * @returns
     */
    static getHouseToMatrlsList(id) {
        return request.get(`${ScmUrl}/yywarehouses/${id}/matrls`);
    }

    /**
     * 查询即时库存物料价格
     * @param {} mid
     * @returns
     */
    static postCurinventoryPrice(mid, data) {
        return request.post(`${ScmUrl}/curinventorys/${mid}/price`, data);
    }
    /**
     * 查询批次饲料价格详情
     * @param {} mid
     * @returns
     */
    static getFeedPrices(id) {
        return request.get(`${CBSUrl}/breedbatchfeedprices/by/${id}`);
    }
}
